<?php
// +----------------------------------------------------------------------
// | quanli team
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2020 http://www.fistforward.com/ All rights reserved.
// +----------------------------------------------------------------------
// | Author: create by allen.qiang
// +----------------------------------------------------------------------

/**
 * 商品录入
 * 
 * @package 	htdocs
 * @subpackage  quanliadmin
 * @author  	create by allen.qiang
 */
define('ITEM_BRAND', 13);	//商品品牌
class pa_goodsAdd {
    public function execute() {
		global $G_SHOP ;
        if (isset($_REQUEST['operFlg'])) {
            switch($_REQUEST['operFlg']) {
                case 1: //商品录入页面
                    $this->goodsAdd();
                break;
				default:
					$G_SHOP->smarty->assign('error_msg', '参数错误，请审核后再操作');
					$G_SHOP->smarty->display('comm/error.tpl');
				break;	
            }
        }
    }

    /**
     * 商品录入初始化页面
     * @author sunchun
     * 
     */
    private function goodsAdd() {
    	
        global $G_SHOP;
        
         $ary_array = array(
         	'sortname' => 'sortOrder',
         	'sortorder' => 'asc',
         	'useFlg' => 1
         );
       
        //分类
        quanli_include('module/base/goods/goodsCategory.class.php');
        $categoryHandler = new goodsCategory( $G_SHOP->DBCA );
        $category = $categoryHandler->searchBigCategory($ary_array);
        
        //商品基本信息
        quanli_include('module/base/goods/goodsBasic.class.php');
        $basicHandler = new goodsBasic( $G_SHOP->DBCA );
        $basicGroup = $basicHandler->searchBasicGroup($ary_array);
        
        //原材料信息
        quanli_include('module/base/goods/goodsMater.class.php');
        $materHandler = new goodsMater( $G_SHOP->DBCA );
        $mater = $materHandler->searchMater($ary_array);
        
        //促销标签
        quanli_include('module/base/goods/goodsPromotion.class.php');
        $tagHandler = new goodsPromotion( $G_SHOP->DBCA );
        $promotionTag = $tagHandler->searchPromotionTag( $ary_array );
        
        //商品标签
        $goodsTag = array();
        quanli_include('module/base/goods/goodsTag.class.php');
        $tagHandler = new goodsTag( $G_SHOP->DBCA );
        $tagGroup = $tagHandler->goodsTagGroupList( $ary_array );
        if ($tagGroup) {
        	foreach ($tagGroup as $group) {
	        	$goodsTag[$group['tagGroupID']]['tagGroupID'] = $group['tagGroupID'];
	        	$goodsTag[$group['tagGroupID']]['tagGroupName'] = $group['tagGroupName'];
	        	$goodsTag[$group['tagGroupID']]['memoName'] = $group['memoName'];
	        	
        		$tag_array = array(
        			'sortname' => 'sortOrder',
		         	'sortorder' => 'asc',
		         	'useFlg' => 1,
		         	'tagGroupID' => $group['tagGroupID']
        		);
        		$tag_array = $tagHandler->goodsTagList( $tag_array );
        		if ($tag_array) {
        			foreach ($tag_array as $tag) {
        				$goodsTag[$group['tagGroupID']]['tag'][] = array(
	        				'tagID' => $tag['tagID'],
	        				'tagName' => $tag['tagName'],
	        				'memoName' => $tag['memoName'],
	        				'tagGroupID' => $tag['tagGroupID'],
	        				'tagGroupName' => $tag['tagGroupName'],
	        				'tagGroupMemoName' => $tag['tagGroupMemoName'],
	        				'sortOrder' => $tag['sortOrder'],
	        				'useFlg' => $tag['useFlg']
	        			);
        			}
        		}
        	}
        }
        
        //品牌
        quanli_include('module/base/system/itemHandler.class.php');
        $itemHandler = new itemHandler( $G_SHOP->DBCA );
        $item_array = array(
        	'useFlg' => 1,
        	'itemCategoryID' => ITEM_BRAND
        );
        $brand_array = $itemHandler->searchItem( $item_array );

        //城市
        $G_SHOP->smarty->assign_by_ref('city', $G_SHOP->getCache('city'));
        $G_SHOP->smarty->assign_by_ref('category', $category);
        $G_SHOP->smarty->assign_by_ref('basicGroup', $basicGroup);
        $G_SHOP->smarty->assign_by_ref('mater', $mater);
        $G_SHOP->smarty->assign_by_ref('promotionTag', $promotionTag);
        $G_SHOP->smarty->assign_by_ref('goodsTag', $goodsTag);
        $G_SHOP->smarty->assign_by_ref('brand_array', $brand_array);
    	$G_SHOP->smarty->display('goods/goodsAdd.tpl');	
    }
}